<template>
    <div class="lists">
        <van-search @click="goSearch" placeholder="请输入搜索关键词" />
        <div class="list-con">
            <div class="nav-list">
                <van-sidebar v-model="active" @change="onChange">
                    <van-sidebar-item title="上装" />
                    <van-sidebar-item title="下装" />
                    <van-sidebar-item title="配饰" />
                    <van-sidebar-item title="鞋履" />
                    <!-- <van-sidebar-item title="服配" />
                    <van-sidebar-item title="生活" /> -->
                </van-sidebar>
            </div>
            <div class="list-shopping">
                <van-grid :border="false" :column-num="3">
                    <van-grid-item @click="goLists(item.name)" v-for="item in l.list" :key="item.id">
                        <van-image :src="require('@/static/image/' + item.img)" />
                        <p>{{ item.name }}</p>
                    </van-grid-item>
                    <!-- <van-grid-item>
                        <van-image src="https://tse3-mm.cn.bing.net/th/id/OIP-C.Ug0gifrEKNO4T50l25PdMQHaLH?w=145&h=217&c=7&r=0&o=5&dpr=1.2&pid=1.7" />
                        <p>T恤</p>
                    </van-grid-item> -->
                </van-grid>
            </div>
        </div>
    </div>
</template>

<script lang="ts" setup>
import { getLists } from "../../api/index";
import { ref, reactive } from "vue";
import { useRouter, useRoute } from "vue-router";
import { showToast } from "vant";

let router = useRouter();
let route = useRoute();

const active = ref(0);
//存放分类页的数据
let listsArr = reactive({
    list: [],
});
//存放显示的分类数据
let l = reactive({
    list: [],
});

//上装：卫衣 夹克 T恤 衬衫 外套
//下装：休闲裤 工装裤 牛仔裤 七分裤 九分裤 短裤
//配饰：胸针 球帽 太阳镜 项链 耳钉
//鞋履：休闲鞋 运动鞋 雪地鞋 拖鞋 凉鞋

const onChange = (index: number) => {
    l.list = listsArr.list[index].list;
    // console.log(l);
};

const goLists = (title: string) => {
    router.push({
        name: "mylists",
        query: {
            title,
        },
    });
};

const goSearch = () => {
    router.push({
        path: "/search",
    });
};
//获取分类导航
getLists().then((res: any) => {
    // console.log(res);
    let { lists } = res.result;
    listsArr.list = lists;
    // console.log(listsArr);
    l.list = lists[0].list;
});
</script>

<style lang="scss" scoped>
.list-con {
    width: 100%;
    padding-top: 54px;
    display: flex;
    .nav-list {
        width: 22%;
        z-index: 1;
        position: fixed;
        top: 54px;
        left: 0;
        :deep(.van-sidebar-item--select:before) {
            //括号中为需要修改的类名
            background-color: #c7273a;
        }
        :deep(.van-sidebar-item) {
            padding: 10px 10px;
            text-align: center;
            background: #fff;
        }
        :deep(.van-sidebar-item--select) {
            text-align: center;
            font-size: 16px;
        }
    }
    .list-shopping {
        border-left: 1px solid #f0f0f0;
        // flex-grow: 1;
        width: 78%;
        margin-left: auto;
        padding-bottom: 60px;

        p {
            padding-top: 5px;
            width: 100%;
            text-align: center;
            font-size: 14px;
            color: #999;
        }
        :deep(.van-grid-item__content--center) {
            justify-content: flex-end;
        }
    }
}
:deep(.van-search) {
    z-index: 1;
    width: 100%;
    position: fixed;
    top: 0;
    left: 0;
}
</style>
